package com.gwcloud.leetcode.tags.backtrace;

/** 
* @ClassName   : Leetcode1079 
* @author      : ganwei 
* @date        : 2020年5月12日 
* @Description : 1079. 活字印刷 
*/
public class Leetcode1079 {
	int result = 0;
	/**
	 * -回溯算法
	 */
    public int numTilePossibilities(String tiles) {
    	int[] counter = new int[26];
    	for(int i = 0; i < tiles.length(); i++) {
    		counter[tiles.charAt(i)-'A']++;
    	}
    	
    	return backtrack(counter);
    }
    /**
     * -回溯主体
     */
    public int backtrack(int[] counter) {
    	int sum = 0;
    	
    	for(int i = 0; i < 26; i++) {
    		if(counter[i] > 0) {
    			sum++;
    			counter[i]--;
    			sum += backtrack(counter);
    			counter[i]++;
    		}
    	}
    	
    	return sum;
    }
    /**
     * -主函数逻辑
     */
    public static void main(String[] args) {
    	Leetcode1079 l1079 = new Leetcode1079();
    	int sum = l1079.numTilePossibilities("AAB");
    	System.out.println(sum);
    }

}
